import * as actionTypes from './actionTypes'
import { fromJS } from 'immutable'
import axios from 'axios'

const searchList = (data) => ({
    type: actionTypes.GET_HOT_SEARCH,
    data: fromJS(data),
    totalPage: Math.ceil(data.length / 10)
})

export const searchFocus = () => ({
    type: actionTypes.SEARCH_FOCUS
})

export const searchBlur = () => ({
    type: actionTypes.SEARCH_BLUR,
})

export const mouseEnter = () => ({
    type: actionTypes.MOUSE_ENTER,
})

export const mouseLeave = () => ({
    type: actionTypes.MOUSE_LEAVE,
})

export const changePage = (page) => ({
    type: actionTypes.CHANGE_PAGE,
    page
})
// 获取热门搜索的action
export const getHotSearch = () => {
    return (dispatch) => {
        axios.get("api/headerList.json").then((res) => {
            const data = res.data.data;
            dispatch(searchList(data))
        }).catch(() => {
            console.log('error')
        })
    }
}